<div class="layuimini-container layuimini-page-anim">
    <div class="layuimini-main">



        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>

        <script type="text/html" id="currentTableBar">
            <a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" lay-event="update">修改</a>
        </script>

    </div>
</div>

<script>
    layui.use(['form', 'table','miniPage','element', 'axios'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table,
            miniPage = layui.miniPage;
        var axios = layui.axios;
        //重新加载 table
        window.reload=function(){
            table.reload('currentTableId');
        }

        //重新加载 table
        window.reload=function(){
            table.reload('currentTableId');
        }


        table.render({
            elem: '#currentTableId',
            url: 'http://localhost:9999/patient/queryAll2',
            toolbar: '#toolbarDemo',
            defaultToolbar: ['filter', 'exports', 'print', {
                title: '提示',
                layEvent: 'LAYTABLE_TIPS',
                icon: 'layui-icon-tips'
            }],
            cols: [[
                // {type: "checkbox", width: 50},
                // {field: 'id', width: 80, title: 'ID', sort: true},
                {field: 'username', width: 100, title: '用户名'},
                {field: 'realname', width: 100, title: '真实姓名'},
                {field: 'sex', width: 80, title: '性别'},
                {field: 'tel', width: 120, title: '电话'},
                {field: 'email', width: 150, title: '邮箱'},
                {title: '操作', minWidth: 150, toolbar: '#currentTableBar', align: "center"}
            ]],
            skin: 'line'
        });

        // 监听搜索操作
        form.on('submit(data-search-btn)', function (data) {
            var username=data.field.username;
            var email=data.field.email;
            //执行搜索重载
            table.reload('currentTableId', {
                page: {
                    curr: 1
                }
                , where: {
                    username: username,
                    email:email
                }
            }, 'data');

            return false;
        });



        //渲染数据 编辑
        function setFormValues(data){
            form.val('updateSubmit',{
                "id":data.id,
                "username":data.username,
                "password":data.password,
                "sex":data.sex,
                "tel":data.tel,
                "email":data.email,
                "info":data.info,
                "realname":data.realname
            });
        }

        table.on('tool(currentTableFilter)', function (obj) {
            var data = obj.data;
            if (obj.event === 'update') {
                var content = miniPage.getHrefContent('page/other2/myupdate.html');
                var openWH = miniPage.getOpenWidthHeight();

                var index = layer.open({
                    title: '编辑用户',
                    type: 1,
                    shade: 0.2,
                    maxmin:true,
                    shadeClose: true,
                    area: [openWH[0] + 'px', openWH[1] + 'px'],
                    offset: [openWH[2] + 'px', openWH[3] + 'px'],
                    content: content,
                });

                //渲染值信息
                setFormValues(data);
                $(window).on("resize", function () {
                    layer.full(index);
                });
                return false;
            }
        });




        //监听表格复选框选择
        table.on('checkbox(currentTableFilter)', function (obj) {
            console.log(obj)
        });



    });
</script>